/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.util.Calendar;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import transformations.Update;


public class Administrateur {

    static boolean isStarted = true;

    public static void main(String[] a) {

        Thread thread = new Thread(new Runnable() {
            @Override
            public synchronized void run() {
                while (isStarted) {
                    Calendar calendar = Calendar.getInstance();
                    int annee = calendar.get(Calendar.YEAR);
                    int mois = calendar.get(Calendar.MONTH);
                    /*int heure= calendar.get(Calendar.HOUR_OF_DAY);
                    if(heure>4 && heure<1){
                        try {
                            Thread.sleep(3600000);
                            continue;
                        } catch (InterruptedException ex) {
                            Logger.getLogger(Administrateur.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    String link = "";
                    if (mois < 8) {
                        link = "http://planning.univ-st-etienne.fr/ade/custom/modules/plannings/anonymous_cal.jsp"
                                + "?resources=&projectId=7&calType=ical&firstDate=" + String.valueOf(annee - 1) + "-09-01&lastDate=" + annee + "-07-20";
                    } else {
                        link = "http://planning.univ-st-etienne.fr/ade/custom/modules/plannings/anonymous_cal.jsp"
                                + "?resources=&projectId=7&calType=ical&firstDate=" + annee + "-09-01&lastDate=" + String.valueOf(annee + 1) + "-07-20";
                    }

                    System.out.println("link: " + link);*/
                    
                    Update u = new Update("");
                    Thread t = new Thread(u);
                    t.start();
                    
                    System.out.println("Mise à jour éffectuée");
                    try {
                        Thread.sleep(10*3600000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Administrateur.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
        thread.start();
        Scanner scanner=new Scanner(System.in);
        System.out.print("appuyer sur n'importe quelle touche puis valider pour arreter le processus des mises à jour\t");
        String s=scanner.next();
        if(s!=null){
            isStarted=false;
            thread.interrupt();
        }

    }
}
